package com.honetooyoung.javaWeb.servlet;

import jakarta.servlet.*;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

public class config extends GenericServlet {
    @Override
    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
        Enumeration<String> names = getInitParameterNames();
        response.setContentType("text/html");
        PrintWriter out=response.getWriter();
        while(names.hasMoreElements()){
            String name=names.nextElement();
            String parameter = getInitParameter(name);
            out.print(name+"="+parameter);
            out.print("^_^<br>");
        }

        ServletContext application=this.getServletContext();
        //获取context path（获取应用上下文的根)
        String contextPath = application. getContextPath();
        out.print(contextPath + "<br>" );
        //获取文件的绝对路径
        //后面的这个路径，加了一个“/"，这个“/"代表的是web的根
        //String realPath = application.getRealPath(" /index.html");//可以
        // 你不加“/"，默认也是从根下开始找。
        //String realPath = this.getRealPath("index.html");
        // 不加“/"也可以
        // out.print(realPath + "<br>");
        String realPath = application.getRealPath("/common/common.html");
        out.print(realPath + "<br>");


    }
}
